<template>
  <div class="managesee">
    <div v-if="isShow">
      <TopFilter
        :list="topFilterList"
        :cols="3"
        @filterChange="changeHandle"
        @onCollapse="collapseHandle"
      ></TopFilter>

      <FilterTable
        ref="table"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        :isSelectColumn="false"
        :onColumnsChange="columns => this.columns = columns"
      >
      </FilterTable>
    </div>
    <!-- 详情 -->
    <info v-else :formData="formData" @close="closeHandler" />
    <!-- <div class="manageSeeInfo" v-else></div> -->
  </div>
</template>

<script>
import { getManageseeData,updateStatus,notification} from '@/api/common/notice/noticemanage/managesee/';
import { dictionary } from '@/utils/dictMixin';
import info from './info'
import { formatDates,formatDat } from '@/utils/validate';
import {getComOrgTreeList,getComOrgTreeLists} from '@/api/common/org/employeeInfo';
import { getJsonTree } from '@/utils/index';
export default {
  name: 'managesee',
  mixins: [dictionary],
  data() {
    return {
      isShow:true,
      topFilterList: this.createTopFilters(),
      fetchParams: {},
      visible: false,
      dialogTitle: '',
      fetchApi: getManageseeData,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      conf:{ add: '新增', edit: '设置',  },
      dataType:'',
      orgName:"",
    };
  },
  components: {
    info
  },
  methods: {
    createTopFilters() {
        return [   
            {
            type: 'SELECT',
            label: '公告类别',
            fieldName: 'notificationType',
            placeholder: '公告类别',
            style: { width: '200px' },
            itemList: this.createDictList('2561'),
            }, 
            {
            type: 'INPUT',
            label: '标题',
            fieldName: 'notificationTitle',
            placeholder: '请输入...',
            initialValue: '',
            style: { width: '200px' },
            },
            {
            type: 'INPUT',
            label: '发布人',
            fieldName: 'publishPerson',
            placeholder: '发布人',
            style: { width: '200px' },
            },
            {
            type: 'SELECT',
            label: '紧急程度',
            fieldName: 'urgency',
            placeholder: '紧急程度',
            style: { width: '200px' },
            itemList: this.createDictList('2562'),
            },
            {
            type: 'RANGE_DATE',
            label: '发布时间',
            fieldName: 'startTime|endTime',
            placeholder: '请输入...',
            initialValue: '',
            style: { width: '240px' },
            },
            
        ];
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          /*1.14需求没有
          <el-button size="mini" v-show={props.row.noticeConfirm1 == 70421001?false:true} type="text" onClick={() => this.editHandle(props.row,"确认")}>
                  确认
                </el-button> 
           */
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row,"查看")}>
                  查看
                </el-button>
                
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '发布时间',
          dataIndex: 'publishDate',
          sorter: true,
          width: 150,
          //filter: true,
          filterType: 'input',
          render: props => {
            return <span>{ formatDates(props.row.publishDate)}</span>;
          }
        },
        {
          title: '有效期至',
          dataIndex: 'endTime',
          sorter: true,
          width: 150,
          //filter: true,
          filterType: 'input',
          render: props => {
            return <span>{formatDat(props.row.endTime)}</span>;
          }
        },
        {
          title: '公告类别',
          dataIndex: 'notificationType',
          sorter: true,
          width: 150,
          //filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('2561'),
          render: props => {
            return <span>{this.createDictText(props.row.notificationType, '2561')}</span>;
          }
        },
        {
          
          title: '标题',
          dataIndex: 'notificationTitle',
          sorter: true,
          //filter: true,
          // width: 100,
          filterType: 'input'
        },
        {
          
          title: '紧急程度',
          dataIndex: 'urgency',
          sorter: true,
          //filter: true,
          width: 100,
          filterType: 'checkbox',
          filterItems: this.createDictList('25612'),
          render: props => {
            return <span>{this.createDictText(props.row.urgency, '2562')}</span>;
          }
        },
        {
          
          title: '发起部门',
          dataIndex: 'publishOrgId',
          sorter: true,
          //filter: true,
          width: 100,
          filterType: 'checkbox',
          filterItems: [],
          render: props => {
            let  OrgTree = this.columns[7].filterItems
            let orgName=''
            if(props.row.publishOrgId){
              OrgTree.map(x=>{
                if(x.value == props.row.publishOrgId){
                  orgName=x.text
                }
              })
            }
            return <span>{orgName}</span>;
          }
        },
        {
          
          title: '发布人',
          dataIndex: 'publishPerson',
          sorter: true,
          //filter: true,
          width: 100,
          filterType: 'input'
        },
        {
          title: '公告来源',
          dataIndex: 'dataType',
          hidden:false,
          sorter: true,
          width: 140,
          //filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1046'),
          render: props => {
            return <span>{this.createDictText(props.row.dataType, '1046')}</span>;
          }
        },
        {
          title: '阅读状态',
          dataIndex: 'readStatus',
          sorter: true,
          //filter: true,
          width: 100,
          filterType: 'input',
          render: props => {
            return <span>{props.row.readStatus==0?"未读":"已读"}</span>;
          }
        },
        /* {
          title: '公告时间',
          dataIndex: 'msgNoticeTime',
          sorter: true,
          width: 150,
          //filter: true,
          filterType: 'input'
        }, 
        {
          title: '内容',
          dataIndex: 'msgContent',
          sorter: true,
          //filter: true,
          filterType: 'input'
        },
        {
          title: '确认状态',
          dataIndex: 'noticeConfirm1',
          sorter: true,
          width: 100,
          //filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('7042'),
          render: props => {
            return <span>{this.createDictText(props.row.noticeConfirm1, '7042')}</span>;
          }
        },*/
      ];
    },
     
    getCookie(){
        let allCookie=document.cookie.split(';')
        allCookie.forEach(x=>{
            if(x.indexOf('dataType') > -1 ){
              this.dataType=x.split('=')[1]
            }
        })
        //判断是否为厂端
        if(this.dataType != 10461001){
          this.columns[4].hidden=true
        }else{
          this.columns[4].hidden=false
        }
    },
    async inputTree() {
          const res = await getComOrgTreeList();
          const res2 = await getComOrgTreeLists()
          var that = _.uniq(res.data.concat(res2.data))
          console.log(that,"this.orgName",this.columns)
          that.map(x=>{
            // this.columns.find(item=>item.fieldName == 'publishOrgId')
            this.columns[7].filterItems.push({ text: x.text, value: x.orgId})
          })
          
      },
    editHandle(row,data) {
      this.formData = row;
      if(data == '查看'){
        this.isShow = false;
        console.log(row,"row")
        notification(row.notificationId)
      }else if(data == '确认'){
        // this.fetchParams = { ...this.fetchParams };
        console.log(row,"row")
        row.noticeConfirm1=70421001
        updateStatus(row,row.msgId).then(res=>{}).catch(err=>{})
      }
      // this.showHandler();
    },
    // showHandler() {
    //   this.dialogTitle = `${this.conf[this.handleType]}`;
    //   this.visible = true;
    // },
    // 搜索
    changeHandle(val) {
        console.log(val,"val")
      this.fetchParams = Object.assign({ sort: 'wayId', order: 'desc'}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    // 确认
    confirmHandle(){
      console.log(this.formData,"msgId")
      updateStatus(this.formData,this.formData.msgId).then(res=>{
        if(res.resultCode == 200){
          this.closeHandler()
        }
      }).catch(err=>{})
    },
    // 返回
    closeHandler() {
      this.isShow=true
    },
    /* 
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    } */
    
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.getCookie()
    this.inputTree()
  },
  created() {
  }
};
</script>

<style lang="less" scoped>
/* .manageSeeInfo{
  height: 100%;
  position: relative;
  padding-left: 40px;
  font-size: 16px;
  h3{
    text-align: center;
    font-size: 25px;
    font-weight: 900;
    color: #666;
    line-height: 60px;
  }
  p{
    margin-bottom: 30px;
    span{
      margin-right: 40px;
    }
  }
  .manageSeeInfoCont{
    margin-bottom: 85px;
  }
  .manageSeeInfoBtn{
    
    text-align: center;
  }
} */
</style>
